package com.example.zhangch.myapplication;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.widget.ImageView;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.Volley;
import com.panxw.android.imageindicator.ImageIndicatorView;
import java.util.List;
import  com.panxw.android.imageindicator.ImageIndicatorView;
/**
 * Created by zhangch on 2017/7/13.
 */
public class NetworkImageIndicatorView extends ImageIndicatorView {
    public NetworkImageIndicatorView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public NetworkImageIndicatorView(Context context) {
        super(context);
    }

    public void setupLayoutByImageUrl(List<String> urlList) {
        for (String url : urlList) {
            final ImageView imageView = new ImageView(getContext());
            //load image from url and set to imageView, you can use UIL or Volley to do this work
            //本次我们使用Volley
            //创建一个请求对列
            RequestQueue queue = Volley.newRequestQueue(getContext());
            ImageRequest request = new ImageRequest(url, new Response.Listener<Bitmap>() {
                @Override
                public void onResponse(Bitmap bitmap) {
                    imageView.setImageBitmap(bitmap);
                }
            }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    System.out.println(volleyError);
                }
            });
            queue.add(request);
            addViewItem(imageView);
        }
    }

}